import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [{
  path: '/login',
  component: () =>
    import ('@/views/login/index'),
  hidden: true
},

{
  path: '/softManage/softManage/softwareManageEdit',
  component: () =>
    import ('@/views/softwareManage/softwareManageEdit'),
  hidden: true
},

{
  path: '/404',
  component: () =>
    import ('@/views/404'),
  hidden: true
},
// 软件库首页
{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () =>
      import ('@/views/softwareLibrary/index'),
    meta: {
      title: '软件资料',
      icon: 'ico_nav1@2x'
    }
  }]
},

// 软件库
{
  path: '/dashboard',
  component: Layout,
  hidden: true,
  children: [
    // 子路由配置
    {
      path: 'softwareLibraryDetails',
      component: () =>
        import ('@/views/softwareLibrary/softwareLibraryDetails'),
      hidden: true
    },
    {
      path: 'personDetails',
      component: () =>
        import ('@/views/softwareLibrary/personDetails'),
      hidden: true
    },
  ]
},

// 授权管理
{
  path: '/applyManage',
  component: Layout,
  redirect: '/softManage/softManage',
  name: 'ApplyManage',
  // meta: {
  //   title: '事件处理',
  //   icon: 'applyManage'
  // },
  children: [
    // {
    //   path: 'softManage',
    //   name: 'softManage',
    //   component: () => import('@/views/softwareManage/softwareManage'),
    //   meta: {
    //     title: '文件传输',
    //     icon: 'ico_nav3_high@2x(2)',
    //     breadcrumb: false
    //   }
    // },
    {
      path: 'applyManage',
      name: 'applyManage',
      component: () =>
        import ('@/views/applyList/applyList'),
      meta: {
        title: '事件处理',
        icon: 'applyManage'
      }
    }
    // 子路由配置
    // {
    //   path: 'softwareManageEdit',
    //   component: () => import('@/views/softwareManage/softwareManageEdit'),
    //   hidden: true
    // },
    // {
    //   path: 'secretkeyManageEdit',
    //   component: () => import('@/views/softwareManage/secretkeyManageEdit'),
    //   hidden: true
    // }
  ]
},
// 软件管理
{
  path: '/softManage',
  component: Layout,
  redirect: '/softManage/softManage',
  name: 'SoftManage',
  meta: {
    title: '软件管理',
    icon: 'ico_nav1@2x'
  },
  children: [{
    path: 'softManage',
    name: 'softManage',
    component: () =>
      import ('@/views/softwareManage/softwareManage'),
    meta: {
      title: '软件管理',
      icon: 'ico_nav3_high@2x(2)',
      breadcrumb: false
    }
  },
  // {
  //   path: 'apply',
  //   name: 'apply',
  //   component: () => import('@/views/applyList/applyList'),
  //   meta: {
  //     title: '授权申请',
  //     icon: 'ico_nav1@2x'
  //   }
  // },
  // 子路由配置
  {
    path: 'softwareManageEdit',
    component: () =>
      import ('@/views/softwareManage/softwareManageEdit'),
    hidden: true
  },
  {
    path: 'secretkeyManageEdit',
    component: () =>
      import ('@/views/softwareManage/secretkeyManageEdit'),
    hidden: true
  }
  ]
},

// 已安装
{
  path: '/installed',
  component: Layout,
  children: [{
    path: 'installed',
    name: 'installed',
    component: () =>
      import ('@/views/installed/index'),
    meta: {
      title: '已装软件',
      icon: 'ico_nav2@2x'
    }
  },
  // 子路由配置
  {
    path: 'softwareLibraryDetails',
    component: () =>
      import ('@/views/softwareLibrary/softwareLibraryDetails'),
    hidden: true
  }
  ]
},
// 用户管理
{
  path: '/userManage',
  component: Layout,
  redirect: '/userManage/userManage',
  name: 'UserManage',
  // meta: {
  //   title: '用户管理',
  //   icon: 'ico_nav4'
  // },
  children: [{
    path: 'userManage',
    name: 'userManage',
    component: () =>
      import ('@/views/userManage/userManage'),
    meta: {
      title: '用户管理',
      icon: 'ico_nav4'
    }
  }]
},

// 资产管理
// {
//     path: '/assetsManage',
//     component: Layout,
//     redirect: '/assetsManage/assetsSoft',
//     name: 'AssetsManage',
//     meta: {
//         title: '资产管理',
//         icon: 'ico_nav1@2x'
//     },
//     children: [{
//         path: 'assetsSoft',
//         name: 'assetsSoft',
//         component: () =>
//             import ('@/views/assetsSoft/assetsSoft'),
//         meta: {
//             title: '硬件固定资产',
//             icon: 'ico_nav1@2x'
//         }
//     }, {
//         path: 'assetsHardware',
//         name: 'assetsHardware',
//         component: () =>
//             import ('@/views/assetsHardware/assetsHardware'),
//         meta: {
//             title: '软件固定资产',
//             icon: 'ico_nav1@2x'
//         }
//     }]
// },
// 台账管理
{
  path: '/accountManage',
  component: Layout,
  redirect: '/accountManage/assetsSoft',
  name: 'AccountManage',
  meta: {
    title: '台账管理',
    icon: 'usrManage'
  },
  children: [{
    path: 'assetsSoft',
    name: 'assetsSoft',
    component: () =>
      import ('@/views/accountManage/assetsSoft'),
    meta: {
      title: '固定资产',
      icon: 'usrManageyingjian'
    }
  }, {
    path: 'assetsHardware',
    name: 'assetsHardware',
    component: () =>
      import ('@/views/accountManage/assetsHardware'),
    meta: {
      title: '软件资产',
      icon: 'usrManagerjian'
    }
  }, {
    path: 'genuineSoftwareUse',
    name: 'genuineSoftwareUse',
    component: () =>
      import ('@/views/accountManage/genuineSoftwareUse'),
    meta: {
      title: '软件使用台账',
      icon: 'usrManageUser'
    }
  }, {
    path: 'genuineSoftwareMaintain',
    name: 'genuineSoftwareMaintain',
    component: () =>
      import ('@/views/accountManage/genuineSoftwareMaintain'),
    meta: {
      title: '软件维护台账',
      icon: 'usrManageweihu'
    }
  }]
},
// 日志
{
  path: '/history',
  component: Layout,
  children: [{
    path: 'history',
    name: 'history',
    component: () =>
      import ('@/views/history/history'),
    meta: {
      title: '日志查看',
      icon: 'ico_nav3@2x'
    }
  }]
},
// 404 page must be placed at the end !!!
{
  path: '*',
  redirect: '/404',
  hidden: true
}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
